// 定义渲染接口（函数指针结构体）
typedef struct Renderer {
    void (*render_circle)(struct Renderer*, float x, float y, float radius);
    void (*render_rect)(struct Renderer*, float x, float y, float w, float h);
} Renderer;

// OpenGL实现
void opengl_render_circle(Renderer* self, float x, float y, float radius) {
    printf("OpenGL: Drawing circle at (%f, %f) with radius %f\n", x, y, radius);
}

void opengl_render_rect(Renderer* self, float x, float y, float w, float h) {
    printf("OpenGL: Drawing rect at (%f, %f) with size %f x %f\n", x, y, w, h);
}

Renderer OpenGLRenderer = {
    .render_circle = opengl_render_circle,
    .render_rect = opengl_render_rect
};

// Vulkan实现（类似，省略）

// 形状基类，组合了Renderer接口
typedef struct Shape {
    Renderer* renderer;  // 桥接的关键：持有实现接口
    void (*draw)(struct Shape*);
} Shape;

// 圆形子类
typedef struct Circle {
    Shape base;
    float x, y, radius;
} Circle;

void Circle_draw(Shape* shape) {
    Circle* self = (Circle*)shape;
    self->base.renderer->render_circle(self->base.renderer, self->x, self->y, self->radius);
}

// 矩形子类（类似，省略）

int main() {
    // 创建形状并绑定渲染器
    Circle circle = {
        .base = { .renderer = &OpenGLRenderer, .draw = Circle_draw },
        .x = 10, .y = 20, .radius = 5
    };

    // 绘制
    circle.base.draw((Shape*)&circle);
    return 0;
}
